from boot import QLabel, QVBoxLayout, QWidget, Union, Signal, List


__all__ = ["_QQ9PagerButtonBase"]

# 模式1
# 1页
# 2页
# 3页
# 4页
# 5页
# 6页
# 7页
# 8页
# 9页
class _QQ9PagerButtonBase(QLabel):

    # 页码按钮池
    page_button_pool: List[QLabel] = []
    # 当前选中页码
    current_select_page: str = "1"
    # 按下信号
    sgn_clicked = Signal(str)

    def __init__(self,
                 parent: Union[QWidget, None] = None,
                 text: str = "",
                 is_page_button: bool = False
                 ):
        super().__init__(parent)

        # 初始化属性
        self.is_page_button = is_page_button

        # 初始化文本
        self.setText(text)

        # 初始化样式
        if _QQ9PagerButtonBase.current_select_page == text:
            self.set_style_sheet_1()
        else:
            self.set_style_sheet_0()

        # 如果是页码按钮，则添加到页码按钮池中
        if self.is_page_button:
            _QQ9PagerButtonBase.page_button_pool.append(self)

    def set_style_sheet_0(self) -> None:
        self.setStyleSheet(
        """
        _QQ9PagerButtonBase {
            font-family: "微软雅黑";
            font-size: 14px;
            color: #000000;
            background-color: #FFFFFF;
            border-radius: 5px;
            border: 1px solid #E3E5E7;
        }
        _QQ9PagerButtonBase:focus {
            background-color: #E3E5E7;
        }
        """
        )

    def set_style_sheet_1(self) -> None:
        self.setStyleSheet(
        """
        _QQ9PagerButtonBase {
            font-family: "微软雅黑";
            font-size: 14px;
            color: #FFFFFF;
            background-color: #0099FF;
            border-radius: 5px;
            border: 1px solid #0099FF;
        }
        """
        )

    def set_style_sheet_2(self) -> None:
        self.setStyleSheet(
        """
        _QQ9PagerButtonBase {
            font-family: "微软雅黑";
            font-size: 14px;
            color: #FFFFFF;
            background-color: #transparent;
            border: none;
        }
        """
        )

    def set_value(self, text: str):
        self.setText(text)

    @property
    def value(self) -> str:
        return self.text()

    def mousePressEvent(self, event):
        self.sgn_clicked.emit(self.value)
        if self.is_page_button:
            self.set_style_sheet_1()
            _QQ9PagerButtonBase.current_select_page = self.value
            for i in _QQ9PagerButtonBase.page_button_pool:
                if i.value != self.value:
                    if i.value == "...":
                        i.set_style_sheet_2()
                    else:
                        i.set_style_sheet_0()
        else:
            self.set_style_sheet_0()






